<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    public function channel()
    {
        return $this->belongsTo(Channel::class);
    }

    public function getAlterAttribute($value)
    {
        return explode(',', $value);
    }

    public function setAlterAttribute($value)
    {
        $this->attributes['alter'] = implode(',', $value);
    }

    /**
     * 是否推荐 0=不推荐 1=推荐
     */
    const RECOMMEND = 1, NOT_RECOMMEND = 0;

    /**
     * 是否发布 0发布 1=发布
     */
    const RELEASE = 1, NOT_RELEASE = 0;

    const RECOMMEND_MAP = [
        self::NOT_RECOMMEND => '不推荐',
        self::RECOMMEND     => '推荐'
    ];

    const RELEASE_MAP = [
        self::NOT_RELEASE => '不发布',
        self::RELEASE     => '发布'
    ];
}
